// pages/member-songCoins2/member-songCoins2.js
import api from '../../utils/api.js'
let app = getApp();
import {
    HTTP
} from '../../utils/http.js';
import { config } from '../../utils/config'
let http = new HTTP();
Page({

    /**
     * 页面的初始数据
     */
    data: {
        // 此页面 页面内容距最顶部的距离
        height: app.globalData.height * 2 + 20,
        showModel: false, // 模态窗口
        showDetail: false, //展示 规则
        gebi_list: [],
        new_gebi_num: 0,
        imgUrl: config.imgUrl,
    },
    // 展示规则
    showDetail(e) {
        let showDetail = this.data.showDetail;
        let showModel = this.data.showModel;

        this.setData({
            showDetail: !showDetail,
            showModel: !showModel
        })

    },
    close(e) {
        this.setData({

            showDetail: false,
            showModel: false
        })
    },
    onLoad: function(options) {
        let user_id = wx.getStorageSync('user_id');
        this.getGebiList(user_id);
        this.getIntegralRule(2).then((res) => {

            let employ = res.employ.split('；');
            let gain = res.gain.split('；')
            this.setData({
                rule: res,
                employ,
                gain
            })
        })

    },
    //拿到用户的银歌币数以及银歌币使用历史
    getGebiList(id) {
        http.request({
            url: api.getGebiList,
            data: {
                id: id
            },
            success: (res) => {
                console.log(res)
                if (res.error_code == 40003) {
                    this.setData({
                        errMsg: "您还没有银歌币历史"
                    })
                }
                if (res.code == 200) {
                    let gebi_list = res.data.gebi_list;
                    let new_gebi_num = res.data.new_gebi_num
                    this.setData({
                        new_gebi_num,
                        gebi_list
                    })
                }
            }
        })
    },
    //拿到规则——1代表积分规则——2代表银歌币规则
    getIntegralRule(id) {
        return new Promise((resolve) => {
            http.request({
                url: api.getIntegralRule,
                data: {
                    id: id
                },
                success: (res) => {
                    console.log('拿到的规则', res)
                    resolve(res)
                }
            })
        })

    },
})